package com.lack.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lack.openApicommon.model.entity.InterfaceInfo;
import com.lack.openApicommon.service.InnerInterfaceInfoService;
import com.lack.project.service.InterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * 内部接口信息服务实现类
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

    @Resource
    private InterfaceInfoService interfaceInfoService;

    /**
     * 根据请求路径和请求方法获取接口信息
     *
     * @param url
     * @param method
     * @return
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {

        if (StringUtils.isAnyBlank(url, method)) {
            throw new RuntimeException("请求参数为空");
        }
        QueryWrapper<InterfaceInfo> interfaceInfoQueryWrapper = new QueryWrapper<>();
        interfaceInfoQueryWrapper.eq("url", url);
        interfaceInfoQueryWrapper.eq("method", method);
        InterfaceInfo interfaceInfo = interfaceInfoService.getOne(interfaceInfoQueryWrapper);
        return interfaceInfo;
    }
}
